import { createApp, type App as VueApp } from 'vue'
import {
    renderWithQiankun,
    qiankunWindow,
    type QiankunProps
} from 'vite-plugin-qiankun/dist/helper'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { router } from './router'
import App from './App.vue'

let app: VueApp<Element> | null = null;

function render(container: any) {
    app = createApp(App);
    app.use(router);
    app.use(ElementPlus);
    app.mount(container)
}

if (qiankunWindow.__POWERED_BY_QIANKUN__) {
    renderWithQiankun({
        bootstrap: () => {
            console.log('vue-vite bootstrap');
        },
        mount: (props: QiankunProps) => {
            console.log('vue-vite mount');
            render(props.container?.querySelector('#app'));
        },
        unmount: () => {
            console.log('vue-vite unmount');
            app?.unmount();
        },
        update: () => {
            console.log('vue-vite update');
        }
    })
}
else {
    render('#app');
}


